package com.example.experiment2;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.Spinner;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {
    private EditText schoolNumber;
    private EditText name;
    private RadioGroup sex;
    private Spinner collage;
    private EditText major;
    private EditText schoolClass;

    private Button explicitly;
    private Button implicitly;


    void initViewRef(){
        this.schoolNumber=findViewById(R.id.school_number);
        this.name=findViewById(R.id.name);
        this.sex=findViewById(R.id.sex);
        this.collage=findViewById(R.id.collage);
        this.major=findViewById(R.id.major);
        this.schoolClass=findViewById(R.id.school_class);

        explicitly=findViewById(R.id.explicitly);
        implicitly=findViewById(R.id.implicitly);
    }

    Bundle collectData(){
        Bundle bundle=new Bundle();
        bundle.putString("schoolNumber",schoolNumber.getText().toString());
        bundle.putString("name",name.getText().toString());
        int checkedButtonId=sex.getCheckedRadioButtonId();
        RadioButton checkedButton=findViewById(checkedButtonId);
        bundle.putString("sex",checkedButton.getText().toString());
        bundle.putString("collage",collage.getSelectedItem().toString());
        bundle.putString("major",major.getText().toString());
        bundle.putString("schoolClass",schoolClass.getText().toString());
        return bundle;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initViewRef();

        explicitly.setOnClickListener((view)->{
            Bundle data=collectData();
            Intent intent=new Intent(this, SecondActivity.class);
            intent.putExtras(data);
            startActivity(intent);
        });
        implicitly.setOnClickListener((view)->{
            Bundle data=collectData();
            Intent intent=new Intent("second");
            intent.putExtras(data);
            startActivity(intent);
        });

    }
}